<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../X-admin/css/font.css">
    <link rel="stylesheet" href="../X-admin/css/xadmin.css">
    <script type="text/javascript" src="../X-admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../X-admin/js/xadmin.js"></script>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">

        <form method="post" enctype="multipart/form-data" action="/" class="layui-form">

        </form>
    </div>
</div>
<script>layui.use(['form', 'layer'],
    function() {
        var user_id12=localStorage.getItem("user_id1");
        if (null == user_id12){
            alert("请重新登陆，页面失效");
            window.location.href="login.html";
        }

        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            nikename1: function(value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            },
            pass1: [/(.+){6,12}$/, '密码必须6到12位'],
            repass1: function(value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });


        //先查
        //先查一遍根据id
        var user_id=localStorage.getItem("user_id1");
        $.ajax({
            type:"POST",
            url: "/userIdlist",
            data:({
                user_id:user_id
            }),
            success: function (data) {
                console.log(data);
                if(data.status==200){
                    var  lists = data.data;
                    for (var i = 0; i < lists.length; i++){
                        var html = "";
                        html +=`
              <div class="layui-form-item">
                <label for="user_name" class="layui-form-label">
                    <span class="x-red">*</span>用户的姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_name" name="user_name" required="" value="${lists[i].user_name}" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>添加姓名
                </div>
            </div>


            <div class="layui-form-item">
                <label for="user_personal" class="layui-form-label">
                    <span class="x-red">*</span>个人照
                </label>
                <div class="layui-input-inline">
                   <!--<div id="shows" style="width: 10px;height: 10px;">-->
                     <!---->
					<!--</div>-->
					<span class="shows" id="shows" style="width: 10%"><img src="/imgshows?picName=${lists[i].user_personal}"/></span>
                    <input type="file" id="user_personal" name="user_personal" value="${lists[i].user_personal}" required="" lay-verify="required" onchange="showimgs1()" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>提交之后显示
                </div>
            </div>


            <div class="layui-form-item">
                <label for="user_card" class="layui-form-label">
                    <span class="x-red">*</span>身份证号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_card" name="user_card" required="" value="${lists[i].user_card}" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_head" class="layui-form-label">
                    <span class="x-red">*</span>头像
                </label>
                <div class="layui-input-inline">
                    <span class="show1" id="show1" style="width: 10%"><img src="/imgshows?picName=${lists[i].user_head}"/></span>
                    <input type="file" id="user_head" name="user_head" required="" value="${lists[i].user_head}" lay-verify="required" onchange="showimg1() class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>提交之后显示
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_name_n" class="layui-form-label">
                    <span class="x-red">*</span>账号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_name_n" name="user_name_n" required="" value="${lists[i].user_name_n}" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>输入手机号
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_password" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="user_password" name="user_password" required=""  lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                   请输入密码
                </div>
            </div>


            <div class="layui-form-item">
                <label for="user_password1" class="layui-form-label">
                    <span class="x-red">*</span>请再次输入密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="user_password1" name="user_password1" required="" lay-verify="repass"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_other" class="layui-form-label">
                    <span class="x-red">*</span> 其他
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_other" name="user_other" required="" value="${lists[i].user_other}" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_number" class="layui-form-label">
                    <span class="x-red">*</span>手机号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_number" name="user_number" required="" value="${lists[i].user_number}" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_remarks" class="layui-form-label">
                    <span class="x-red">*</span>备注
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_remarks" name="user_remarks" required="" required="" value="${lists[i].user_remarks}" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_s" class="layui-form-label">
                    <span class="x-red">*</span>说明
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_s" name="user_s" required="" required="" value="${lists[i].user_s}" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_s" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                   修改
                </button>
                 <button  onclick="memberup1()" class="layui-btn" >
                    返回
                </button>
            </div>

                    `
                        $('.layui-form').append(html);
                    }
                }
                if(data.status==500){
                    alert("查询失败");
                    window.location.reload();
                }
            }
        });

        //监听提交
        form.on('submit(add)',
            function(data) {
                console.log(data);
                var fordata = new FormData();
                fordata.append('user_id',localStorage.getItem("user_id"));
                fordata.append('user_name',$('#user_name').val());
                fordata.append('user_card',$('#user_card').val());
                fordata.append('user_name_n',$('#user_name_n').val());
                fordata.append('user_password',$('#user_password').val());
                fordata.append('user_other',$('#user_other').val());
                fordata.append('user_number',$('#user_number').val());
                fordata.append('user_remarks',$('#user_remarks').val());
                fordata.append('user_s',$('#user_s').val());
                fordata.append('user_personal',$('#user_personal')[0].files[0]);
                fordata.append('user_head',$('#user_head')[0].files[0]);
                $.ajax({
                    type:"post",
                    url:"/updatauser",
                    processData: false,
                    contentType: false,
                    cache:false,
                    async: false,
                    data:fordata,
                    success:function(data) {
                        console.log(data);
                        if(data.status==200) {
                            // alert("修改成功");
                            // window.location.href="myself.html";
                            layer.alert("稍后片刻", {icon: 6},function () {
                                var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                                window.parent.location.reload();//刷新父页面
                                parent.layer.close(index);//关闭弹出层
                            });
                            return;
                        }
                        if(data.status==500) {
                            // alert("添加错误");
                            // window.location.href="myself.html";
                            layer.alert("稍后片刻", {icon: 2},function () {
                                var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                                window.parent.location.reload();//刷新父页面
                                parent.layer.close(index);//关闭弹出层
                            });
                            return;
                        }
                        if(data.status==null) {
                            // alert("修改异常");
                            // window.location.href="myself.html";
                            layer.alert("稍后片刻", {icon: 2},function () {
                                var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                                window.parent.location.reload();//刷新父页面
                                parent.layer.close(index);//关闭弹出层
                            });
                            return;
                        }
                        if(data.status==20) {
                            layer.alert("重复添加", {icon: 3},function () {
                                var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                                parent.layer.reload(index);
                            });
                            return;
                        }
                    }
                });
                return false;
            });

    });
function memberup1() {
        var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
        window.parent.location.reload();//刷新父页面
        parent.layer.close(index);//关闭弹出层
}

function showimgs() {
    var filePath= $("#user_personal").val();
    if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(filePath)){
        alert('"提示", "请上传图片（格式BMP、JPG、JPEG、PNG、GIF等）!"');
    }else{

        var url = null;
        var fileimg = document.getElementById("user_personal").files[0];
        if(window.createObjectURL != undefined){
            url = window.createOjcectURL(fileimg);
        }
        else if(window.URL != undefined){
            url = window.URL.createObjectURL(fileimg);
        }else if(window.webkitURL != undefined){
            url = window.webkitURL.createObjectURL(fileimg)
        }
        var html ="";
        html+='<img src="'+url+'" style="width: 100px;height: 100px;margin-left:400px;margin-top:-120px"/>';
        $("#shows").html("");
        $("#shows").html(html);
    }
}

function showimg() {
    var filePath= $("#user_head").val();
    if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(filePath)){
        alert('"提示", "请上传图片（格式BMP、JPG、JPEG、PNG、GIF等）!"');
    }else{

        var url = null;
        var fileimg = document.getElementById("user_head").files[0];
        if(window.createObjectURL != undefined){
            url = window.createOjcectURL(fileimg);
        }
        else if(window.URL != undefined){
            url = window.URL.createObjectURL(fileimg);
        }else if(window.webkitURL != undefined){
            url = window.webkitURL.createObjectURL(fileimg)
        }
        var html ="";
        html+='<img src="'+url+'" style="width: 100px;height: 100px;margin-left:400px;margin-top:-120px"/>';
        $("#show1").html("");
        $("#show1").html(html);
    }
}
</script>

</body>

</html>
